package adapter;

import com.example.lastprojectbeautiplus.R;

import utils.Comment;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class CommentListViewAdapter extends ArrayAdapter<Comment> {
	private Comment[] commentList;
	private Activity activity;
	private int resource;
	private View view;

	public CommentListViewAdapter(Activity activity, int resource,
			Comment[] commentList) {
		super(activity, resource, commentList);
		// TODO Auto-generated constructor stub
		this.activity = activity;
		this.resource = resource;
		this.commentList = commentList;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return commentList.length;
	}

	public Comment getItem(int position) {
		return commentList[position];
	}

	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		view = convertView;
		if (view == null) {
			LayoutInflater inflater = (LayoutInflater) activity
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = inflater.inflate(resource, null);

		} else
			view = (View) convertView;

		TextView tvUsername = (TextView) view.findViewById(R.id.tvUsername);
		TextView tvComment = (TextView) view.findViewById(R.id.tvComment);
		tvUsername.setText(commentList[position].getUser().getUsername()
				+ " : ");
		tvComment.setText(commentList[position].getContent());
		return view;
	}
}
